void solve()
{
  int n, q;
  cin >> n >> q;

  vl xsum(n + 1), sum(n + 1);
  vi pos, a(n + 1);
  rep(i, 1, n) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    xsum[i] = xsum[i - 1] ^ a[i];
    if (a[i]) {
      pos.pb(i);
    }
  }

  auto calc = [&](int l, int r) {
    return sum[r] - sum[l - 1] - (xsum[r] ^ xsum[l - 1]);
  };

  while (q--) {
    int L, R;
    cin >> L >> R;
    
    ll ret = calc(L, R);
    if (ret == 0) {
      cout << L << ' ' << L << '\n';
      continue;
    }

    int l = lower_bound(all(pos), L) - pos.begin();
    int r = upper_bound(all(pos), R) - pos.begin();
    r--;

    int ansl = L, ansr = R, ans = R - L + 1;
    rep(i, l, r) {
      if (calc(pos[i], pos[r]) < ret) {
        break;
      }
      per(j, r, i) {
        int lp = pos[i], rp = pos[j];
        if (calc(lp, rp) < ret) {
          break;
        }
        if (rp - lp + 1 < ans) {
          ans = rp - lp + 1;
          ansl = lp, ansr = rp;
        }
      }
    }
    cout << ansl << ' ' << ansr << '\n';
  }
}